<?php
namespace app\super\controller;
use think\Db;
use think\Controller;
use  think\Request;


class Index extends Base
{
    public function index()
    {
       
	   return view();
	}
	
	public function dic()
    {
		
		$list=Db::query('select * from dictionary group by name');
		
		$this->assign('alist',$list);
		
		
		return view();
	}
	public function adddickey(){
		
		$request = Request::instance();
		$name =$request->post("name");
		if($request->isPost()){
		
			if($name!=""){
				$obj=Db::execute("insert into  dictionary(name) values('".$name."')");
				  $this->redirect('Index/dic');
			}else{
				$this->success('类别不能为空');
			}
			
		}
		
	}
	public function getdiclist(){
		$request = Request::instance();
		$name =$request->post("name");
		
		$list =db('dictionary')->where("name='".$name."' and value is not null")->select();
		return json($list);
		
	}
	public function deldicval(){
		$request = Request::instance();
		$id =$request->post("id");
		if(db('dictionary')->where("id=".$id)->delete()){
			 return ['status'=>200,'message'=>'删除成功'];
			
		}else{
			
			   return ['status'=>500,'message'=>'删除失败'];
		}
		
	}
	public function deldicname(){
		$request = Request::instance();
		$name =$request->post("name");
		if(db('dictionary')->where("name='".$name."'")->delete()){
			 return ['status'=>200,'message'=>'删除成功'];
			
		}else{
			
			 return ['status'=>500,'message'=>'删除失败'];
		}
	}
	public function adddicdata(){
		$request = Request::instance();
		$name =$request->post("name");
		$value =$request->post("value");
		$data["name"]=$name;
		$data["value"]=$value;
		if(db('dictionary')->insertGetId($data)){
				 return ['status'=>200,'message'=>'添加成功'];
			
		}else{
			return ['status'=>500,'message'=>'添加失败'];
		}
		
	}
}
